#!/bin/sh
main()
{
. $DOCUMENT_ROOT/apps/home/header.tpl.sh
header_html
get_telnetd_setting
cat <<'EOF'
<script>
$(function(){
  $('#post_set_telnetd').on('submit', function(e){
    e.preventDefault();
    var data = "app=telnetd&action=post_set_telnetd&"+$(this).serialize();
    var url = 'index.cgi';
    Ha.common.ajax(url, 'json', data, 'post', 'ajax-fluid');
  });
});
</script>
EOF
cat <<EOF
		<div class="pure-g">
			<div class="l-box-lrg pure-u-1 pure-u-md-1-2">
				<h3>Telnet服务</h3>
				<form class="pure-form pure-form-stacked" id="post_set_telnetd">
					<fieldset>

					<div class="pure-u-1">
						<label>开/关
							<select name="enabled">
								<option value="0" `[ $enabled -eq 0 ] && echo selected`>禁用</option>
								<option value="1" `[ $enabled -ne 0 ] && echo selected`>启用</option>
							</select>
						</label>
						<button class="pure-button">保存</button>
					</div>

					</fieldset>
				</form>
				<br/>
				<br/>
			</div>
			<div class="l-box-lrg pure-u-1 pure-u-md-1-2">
				<div class="content">
				<h3>说明<h3>
				<p>打开可以防御内网arp攻击.</p>
				</div>
			</div>
		</div>
EOF
footer_html keep_bottom
}
post_set_telnetd()
{
if
[ "$FORM_enabled" -eq 1 ]
then
cat <<'EOF' > /etc/init.d/telnet
#!/bin/sh /etc/rc.common
START=50
USE_PROCD=1
PROG=/usr/sbin/telnetd
start_service() {
	procd_open_instance
	procd_set_param command "$PROG" -F -l /bin/login.sh
	procd_close_instance
}
EOF
cat <<'EOF' > /bin/login.sh
#!/bin/sh
exec /bin/login
EOF
/etc/init.d/telnet enable
/etc/init.d/telnet restart 2>&1 >/dev/null
else
/etc/init.d/telnet disable
killall telnetd 2>&1 >/dev/null
fi
echo "修改成功!!" | main.sbin output_json 0
}
get_telnetd_setting()
{
if
ls /etc/rc.d/ | grep -iq "S[0-9]*telnet"
then
str=$(grep -vE "^#|^$" /bin/login.sh)
	if
	[ $(echo "$str" | wc -l) -eq 1 ] && echo "$str" grep -q "/bin/login"
	then
	enabled=1
	else
	enabled=0
	fi
else
enabled=0
fi
[ -z "$1" ] && cat <<EOF

{"enabled": $enabled}
EOF
}
lang=`main.sbin get_client_lang`
eval `cat $DOCUMENT_ROOT/apps/$FORM_app/i18n/$lang/i18n.conf`
if
[ $is_main_page = 1 ]
then
main
elif [ -n "$FORM_action" ]
then
$FORM_action
fi
